package com.fa.controller;

import com.fa.common.core.controller.BaseController;
import com.fa.common.core.domain.AjaxResult;
import com.fa.common.core.page.TableDataInfo;
import com.fa.domain.Location;
import com.fa.domain.LocationSearchVO;
import com.fa.domain.LocationVO;
import com.fa.service.LocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/wm/location")
public class LocationController extends BaseController {
    @Autowired
    private LocationService locationService;

    @GetMapping("/list")
    public TableDataInfo listLocation(LocationSearchVO locationSearchVO){
        startPage();
        List<LocationVO> locationVOS = locationService.listLocation(locationSearchVO);
        return getDataTable(locationVOS);
    }

    @GetMapping("/listById")
    public AjaxResult listLocationById(Long locationId){
        LocationVO locationVO = locationService.listLocationById(locationId);
        return success(locationVO);
    }

    @PostMapping("/add")
    public AjaxResult addLocationList(@RequestBody List<Location> locationList){
        locationService.addLocationList(locationList);
        return success();
    }

    @GetMapping("/del")
    public AjaxResult delLocationList(@RequestParam List<Integer> locationIds){
        locationService.delLocationList(locationIds);
        return success();
    }

    @PostMapping("/update")
    public AjaxResult updateLocation(@RequestBody Location location){
        locationService.updateLocation(location);
        return success();
    }
}
